#usr/bin/python3
# -*- coding: utf-8 -*-

# 此案例运行在位置模式下
import serial
from time import sleep
 
ser = serial.Serial('/dev/minibot',  115200,  timeout=1)
packet = [0xAA,  0x55,  0x07,  0x03,  0x05,  0x01,  0x16,  0x2A,  0x00,  0x00, 0x2A,  0xF8]
ser.write(packet)
sleep(2)
packet = [0xAA,  0x55,  0x07,  0x03,  0x05,  0x01,  0x16,  0x2A,  0xFF,  0x0F, 0x2B,  0x0C]
ser.write(packet)
sleep(2)
packet = [0xAA,  0x55,  0x06,  0x02,  0x04,  0x01,  0x16,  0x38,  0x02,  0xFF, 0x1B]
ser.write(packet)
# sleep(2)

COUNT = 0
def recv(serial):
    global COUNT
    while True:
        COUNT = COUNT + 1
        # sleep(0.03)
        data = serial.read(30)
        if data == '':
            if COUNT > 100:
                break
            continue
        else:
            break
    return data
 
data = recv(ser)
print("COUNT:", COUNT)
# print(data)